import React from 'react'
import { useSelector } from 'react-redux'

interface PermissionProps {
  name: string
  children?: React.ReactNode
}

export default function Permission(props: PermissionProps) {
  const { name } = props
  const permissions = useSelector((state: { common: initStateType }) => state.common.permissions);
  return (
    name && ~permissions.findIndex(n => n.permissionKey === name) &&
    props.children
    || null
  )
}
